import { createHashRouter } from "react-router-dom"
import Layout from "@/pages/Layout/index.js"
import Login from "@/pages/Login/index.js"
import AuthRoute from "@/components/AuthRoute"

//原来的加载方式，首页打开4,5ms左右
// import Home from '@/pages/Home'
// import Publish from '@/pages/Publish'
// import Article from '@/pages/Article'
//路由懒加载，按需加载组件
import { Suspense, lazy } from "react"
const Home=lazy(()=>import("@/pages/Home"))
const Publish=lazy(()=>import('@/pages/Publish'))
const Article=lazy(()=>import('@/pages/Article'))
const router = createHashRouter([
    {
        path: '/',
        element: <AuthRoute><Layout /></AuthRoute>,
        children: [
            {
                // path: 'home',
                index:true,
                //fallback加载前的一些提示信息
                element: <Suspense fallback={'加载中...'}><Home/></Suspense>
            },
            {
                path: 'article',
                element:<Suspense fallback={'加载中...'}><Article /></Suspense>,
            },
            {
                path: 'publish',
                element: <Suspense fallback={'加载中...'}><Publish /></Suspense>,
            },
        ]


    },
    {
        path: 'login',
        element: <Login />
    }
])

export default router